<?php
/**
 * Copyright 2011  SURFfoundation
 * 
 * This file is part of ESCAPE.
 * 
 * ESCAPE is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * ESCAPE is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with ESCAPE.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * For more information:
 * http://escapesurf.wordpress.com/
 * http://www.surffoundation.nl/
 * 
 * Contact: d.vierkant@utwente.nl
 * 
 * @license http://www.gnu.org/licenses/gpl.html GNU GPLv3
 */
?>
<?php
	/* @var $repositoryUi escape_repositoryui_RepositoryUi */
	$repositoryUi =& $this->requestAttributes['repositoryUi'];
	/* @var $oreObject escape_repository_OreObject */
	$oreObject =& $this->requestAttributes['oreObject'];
	/* @var $aggregation escape_repository_OreAggregation */
	$aggregation =& $this->requestAttributes['aggregation'];

	$isAggregation = $this->requestAttributes['isAggregation'];
	$returnUrl = $this->requestAttributes['returnUrl'];

	$gadgetModeUrlParameter = '';
	if($repositoryUi->isGadgetMode())
	{
		$gadgetModeUrlParameter = '?gadget=1';
	}
	
	$repositoryUi->setTemplateFromAggregation($aggregation);
	
	$templateVariables = array();
	$templateVariables['title'] = 'Delete object';
	$this->requestAttributes['templateVariables'] =& $templateVariables;
?>
<?php $this->displayHeader(); ?>

<div class="escape_Section">
<span class="escape_SectionTitle">Delete object</span>
<p>
You are about to delete the following object:
</p>
</div>

<div class="escape_Section">
<form action="/delete/<?php print rawurlencode($oreObject->getId()) . $gadgetModeUrlParameter; ?>" method="post">
<p>
Are you sure?
<button onclick="$(this).disabled = true; $($(this).parentNode).insert(new Element('input', {'type': 'hidden', 'name': 'return_url', 'value': '<?php print escape_javascriptEscape($returnUrl) . $gadgetModeUrlParameter; ?>'})); $($(this).parentNode).insert(new Element('input', {'type': 'hidden', 'name': 'delete_confirm', 'value': '1'})); $(this).form.submit();">Yes</button>
<button onclick="escape_escapeUi.redirectToResourceById('edit', <?php print htmlspecialchars(json_encode($oreObject->getId())); ?>); return false">No</button>
</p>
</form>
</div>

<div class="escape_Selection">
<?php
	// display the selected resource and it's properties
	$repositoryUi->displayOreObject($aggregation, $oreObject, true);
?>
</div>
<?php		
	if(!$isAggregation)
	{
		// this is an aggregated resource
?>
<div class="escape_Relations">
<p>
The following relations will be deleted as well:
<br />
<span class="escape_Note">(Only the relations to and from the objects below will be deleted, not the objects itself)</span>
</p>
</div>

<?php
			
		// display the relations of the selected resource
		$repositoryUi->displayOreObjectRelations($aggregation, $oreObject);
	}
	else
	{
		// this is an aggregation
?>
<div class="escape_Relations">
<p>
The entire <?php print htmlspecialchars($repositoryUi->repository->config['label_aggregation']); ?> will be deleted, including all aggregated resources!
</p>
</div>

<?php
	}
?>

<?php $this->displayFooter(); ?>
